﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;

using CE.Database;
using CE.User;
using CE.TravelInsurance;
using CE.Global;

public partial class promo_rsa_july_travel_insurance : System.Web.UI.Page
{
    private Int32 RowCount = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            #region Set Page Title, Keywords and Description
            Master.Page.Title = lblPageTile.Text;

            //***Add Ref Header (using System.Web.UI.HtmlControls;)***
            HtmlMeta keywords = new HtmlMeta();
            keywords.Name = "keywords";
            keywords.Content = lblKeywords.Text;

            HtmlMeta description = new HtmlMeta();
            description.Name = "description";
            description.Content = lblDescription.Text;

            Page.Header.Controls.AddAt(2, keywords);
            Page.Header.Controls.AddAt(2, description);
            #endregion

            //promo end
            DataTable dtPromo = CheckPromo("24");
            if (dtPromo.Rows.Count <= 0)
            {
                Response.Redirect("promo-coming-soon.aspx");
            }

            LoadCountries();
            LoadRegion();
            ChangeControlSetting();
            ChangeDateSetting();

            if (Session[General.TAId] != null)
            {
                ShowTADetails(Convert.ToInt64(Session[General.TAId].ToString()));
            }

        }
    }

    private void ShowTADetails(Int64 TAId)
    {
        TAApplicantSearchDB _taapplicantsearchdb = new TAApplicantSearchDB();
        TAApplicantSearch _taapplicantsearch = new TAApplicantSearch();

        _taapplicantsearch = _taapplicantsearchdb.GetTAApplicantSearchItem(TAId);

        if (_taapplicantsearch != null)
        {

            //txtFullName.Text = _taapplicantsearch.Name;
            //txtEmail.Text = _taapplicantsearch.EmailAddress;
            //txtMobileNo.PhoneNo = _taapplicantsearch.MobileNum;

            ddlTripType.SelectedValue = _taapplicantsearch.TripType;
            ddlPolicyType.SelectedValue = _taapplicantsearch.PlanType;
            //ddlCoverage.SelectedValue = _taapplicantsearch.CoverageLevel;

            //ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript: ChangeScenario(); ", true);

            if (_taapplicantsearch.TripType == "S")
            {
                ddlDestCountry.SelectedValue = _taapplicantsearch.CountryID.ToString();
                txtCountry.Text = ddlDestCountry.SelectedItem.Text;
                inputSelCountryName.Value = ddlDestCountry.SelectedItem.Text;
                //usrTravelStartDate.Day = _taapplicantsearch.StartddlDestCountry.SelectedItem.Text;Date.Day;
                //usrTravelStartDate.Month = _taapplicantsearch.StartDate.Month;
                //usrTravelStartDate.Year = _taapplicantsearch.StartDate.Year;
                //usrTravelEndDate.Day = _taapplicantsearch.EndDate.Day;
                //usrTravelEndDate.Month = _taapplicantsearch.EndDate.Month;
                //usrTravelEndDate.Year = _taapplicantsearch.EndDate.Year;

                inputFrom.Value = _taapplicantsearch.StartDate.ToString("dd/MM/yyyy");
                inputTo.Value = _taapplicantsearch.EndDate.ToString("dd/MM/yyyy");


            }
            else if (_taapplicantsearch.TripType == "A")
            {
                ddlDestRegion.SelectedValue = _taapplicantsearch.AreaID.ToString();
                //usrPolicyComDate.Day = _taapplicantsearch.StartDate.Day;
                //usrPolicyComDate.Month = _taapplicantsearch.StartDate.Month;
                //usrPolicyComDate.Year = _taapplicantsearch.StartDate.Year;

                inputannualcomdate.Value = _taapplicantsearch.StartDate.ToString("dd/MM/yyyy");

            }

            if (_taapplicantsearch.PlanType == "IND")
            {
                if (_taapplicantsearch.DOBAdult1 != null)
                {
                    usrBirthday.Day = _taapplicantsearch.DOBAdult1.Day;
                    usrBirthday.Month = _taapplicantsearch.DOBAdult1.Month;
                    usrBirthday.Year = _taapplicantsearch.DOBAdult1.Year;
                }
            }
            else if (_taapplicantsearch.PlanType == "FML")
            {


                if (_taapplicantsearch.TripType == "S")
                {
                    ddlNoOfAdultsSingle.Text = _taapplicantsearch.NoofAdults.ToString();
                    ddlNoOfChildsSingle.Text = _taapplicantsearch.NoofChilds.ToString();

                    usrAdult1DOBSingle.Day = _taapplicantsearch.DOBAdult1.Day;
                    usrAdult1DOBSingle.Month = _taapplicantsearch.DOBAdult1.Month;
                    usrAdult1DOBSingle.Year = _taapplicantsearch.DOBAdult1.Year;

                    if (_taapplicantsearch.NoofAdults > 1) //no of adults
                    {
                        usrAdult2DOBSingle.Day = _taapplicantsearch.DOBAdult2.Day;
                        usrAdult2DOBSingle.Month = _taapplicantsearch.DOBAdult2.Month;
                        usrAdult2DOBSingle.Year = _taapplicantsearch.DOBAdult2.Year;
                    }

                    usrChild1DOBSingle.Day = _taapplicantsearch.DOBChild1.Day;
                    usrChild1DOBSingle.Month = _taapplicantsearch.DOBChild1.Month;
                    usrChild1DOBSingle.Year = _taapplicantsearch.DOBChild1.Year;

                    if (_taapplicantsearch.NoofChilds > 1) //no of child
                    {
                        usrChild2DOBSingle.Day = _taapplicantsearch.DOBChild2.Day;
                        usrChild2DOBSingle.Month = _taapplicantsearch.DOBChild2.Month;
                        usrChild2DOBSingle.Year = _taapplicantsearch.DOBChild2.Year;
                    }
                    if (_taapplicantsearch.NoofChilds > 2)
                    {
                        usrChild3DOBSingle.Day = _taapplicantsearch.DOBChild3.Day;
                        usrChild3DOBSingle.Month = _taapplicantsearch.DOBChild3.Month;
                        usrChild3DOBSingle.Year = _taapplicantsearch.DOBChild3.Year;
                    }
                    if (_taapplicantsearch.NoofChilds > 3)
                    {
                        usrChild4DOBSingle.Day = _taapplicantsearch.DOBChild4.Day;
                        usrChild4DOBSingle.Month = _taapplicantsearch.DOBChild4.Month;
                        usrChild4DOBSingle.Year = _taapplicantsearch.DOBChild4.Year;
                    }

                }
                else
                {
                    ddlNoOfAdults.Text = _taapplicantsearch.NoofAdults.ToString();
                    ddlNoOfChilds.Text = _taapplicantsearch.NoofChilds.ToString();

                    usrAdult1DOB.Day = _taapplicantsearch.DOBAdult1.Day;
                    usrAdult1DOB.Month = _taapplicantsearch.DOBAdult1.Month;
                    usrAdult1DOB.Year = _taapplicantsearch.DOBAdult1.Year;

                    if (_taapplicantsearch.NoofAdults > 1) //no of adults
                    {
                        usrAdult2DOB.Day = _taapplicantsearch.DOBAdult2.Day;
                        usrAdult2DOB.Month = _taapplicantsearch.DOBAdult2.Month;
                        usrAdult2DOB.Year = _taapplicantsearch.DOBAdult2.Year;
                    }

                    usrChild1DOB.Day = _taapplicantsearch.DOBChild1.Day;
                    usrChild1DOB.Month = _taapplicantsearch.DOBChild1.Month;
                    usrChild1DOB.Year = _taapplicantsearch.DOBChild1.Year;

                    if (_taapplicantsearch.NoofChilds > 1) //no of child
                    {
                        usrChild2DOB.Day = _taapplicantsearch.DOBChild2.Day;
                        usrChild2DOB.Month = _taapplicantsearch.DOBChild2.Month;
                        usrChild2DOB.Year = _taapplicantsearch.DOBChild2.Year;
                    }
                    if (_taapplicantsearch.NoofChilds > 2)
                    {
                        usrChild3DOB.Day = _taapplicantsearch.DOBChild3.Day;
                        usrChild3DOB.Month = _taapplicantsearch.DOBChild3.Month;
                        usrChild3DOB.Year = _taapplicantsearch.DOBChild3.Year;
                    }
                    if (_taapplicantsearch.NoofChilds > 3)
                    {
                        usrChild4DOB.Day = _taapplicantsearch.DOBChild4.Day;
                        usrChild4DOB.Month = _taapplicantsearch.DOBChild4.Month;
                        usrChild4DOB.Year = _taapplicantsearch.DOBChild4.Year;
                    }
                    if (_taapplicantsearch.NoofChilds > 4)
                    {
                        usrChild5DOB.Day = _taapplicantsearch.DOBChild5.Day;
                        usrChild5DOB.Month = _taapplicantsearch.DOBChild5.Month;
                        usrChild5DOB.Year = _taapplicantsearch.DOBChild5.Year;
                    }
                    if (_taapplicantsearch.NoofChilds > 5)
                    {
                        usrChild6DOB.Day = _taapplicantsearch.DOBChild6.Day;
                        usrChild6DOB.Month = _taapplicantsearch.DOBChild6.Month;
                        usrChild6DOB.Year = _taapplicantsearch.DOBChild6.Year;
                    }
                }
            }
            else if (_taapplicantsearch.PlanType == "INS")
            {
                if (_taapplicantsearch.DOBAdult1 != null)
                {
                    usrBirthday.Day = _taapplicantsearch.DOBAdult1.Day;
                    usrBirthday.Month = _taapplicantsearch.DOBAdult1.Month;
                    usrBirthday.Year = _taapplicantsearch.DOBAdult1.Year;
                }

                if (_taapplicantsearch.DOBAdult2 != null)
                {
                    usrBirthdaySpouse.Day = _taapplicantsearch.DOBAdult2.Day;
                    usrBirthdaySpouse.Month = _taapplicantsearch.DOBAdult2.Month;
                    usrBirthdaySpouse.Year = _taapplicantsearch.DOBAdult2.Year;
                }
            }




        }
    }

    private void LoadRegion()
    {
        DataTable dtRegionArea = General.GetComboItem("RegionArea", true);

        ddlDestRegion.DataSource = dtRegionArea;
        ddlDestRegion.DataTextField = dtRegionArea.Columns[0].ColumnName.ToString();
        ddlDestRegion.DataValueField = dtRegionArea.Columns[1].ColumnName.ToString();
        ddlDestRegion.DataBind();
        ddlDestRegion.Items.Insert(0, new ListItem("Select", "-1"));

        ddlDestRegion.Attributes.Add("onblur", "ShowValidationEffect('" + ddlDestRegion.ClientID + "','" + rfvDestRegion.ClientID + "');");

    }

    private void LoadCountries()
    {
        //DataTable dtCountry = General.GetComboItem("Country", true);

        //Sakthi on 16 Dec 2010  -- Start
        DataTable dtTempCountry = General.GetComboItem("Country", true);
        DataTable dtCountry = new DataTable();

        if (dtTempCountry.Rows.Count > 0)
        {
            DataSet dsCountry = new DataSet();
            for (Int16 i = 0; i < dtTempCountry.Rows.Count; i++)
            {
                if (dtTempCountry.Rows[i]["CountryId"].ToString() == "185")
                {
                    dsCountry = General.RemoveRow(dtTempCountry, i);
                    dtCountry = dsCountry.Tables[0];
                }
                else
                {
                    dtCountry = dtTempCountry;
                }
            }
        }//Sakthi on 16 Dec 2010  -- End

        ddlDestCountry.DataSource = dtCountry;
        ddlDestCountry.DataTextField = dtCountry.Columns[0].ColumnName.ToString();
        ddlDestCountry.DataValueField = dtCountry.Columns[1].ColumnName.ToString();
        ddlDestCountry.DataBind();
        ddlDestCountry.Items.Insert(0, new ListItem("Select", "-1"));

        ddlDestCountry.Attributes.Add("onblur", "ShowValidationEffect('" + ddlDestCountry.ClientID + "','" + rfvDestCountry.ClientID + "');");

    }

    private void ChangeControlSetting()
    {
        ddlTripType.Attributes.Add("onblur", "ShowValidationEffect('" + ddlTripType.ClientID + "','" + rfvTripType.ClientID + "');");
        ddlPolicyType.Attributes.Add("onblur", "ShowValidationEffect('" + ddlPolicyType.ClientID + "','" + rfvPolicyType.ClientID + "');");

        txtCountry.Attributes.Add("onblur", "ShowValidationEffect('" + txtCountry.ClientID + "','" + rfvCountry.ClientID + "');");
        ddlDestCountry.Attributes.Add("onblur", "ShowValidationEffect('" + ddlDestCountry.ClientID + "','" + rfvDestCountry.ClientID + "');");
        ddlDestRegion.Attributes.Add("onblur", "ShowValidationEffect('" + ddlDestRegion.ClientID + "','" + rfvDestRegion.ClientID + "');");
        ddlNoOfAdults.Attributes.Add("onblur", "ShowValidationEffect('" + ddlNoOfAdults.ClientID + "','" + rfvNoOfAdults.ClientID + "');");
        ddlNoOfChilds.Attributes.Add("onblur", "ShowValidationEffect('" + ddlNoOfChilds.ClientID + "','" + rfvNoOfChilds.ClientID + "');");
        ddlNoOfAdultsSingle.Attributes.Add("onblur", "ShowValidationEffect('" + ddlNoOfAdults.ClientID + "','" + rfvNoOfAdults.ClientID + "');");
        ddlNoOfChildsSingle.Attributes.Add("onblur", "ShowValidationEffect('" + ddlNoOfChilds.ClientID + "','" + rfvNoOfChilds.ClientID + "');");

    }

    private void ChangeDateSetting()
    {

        usrAdult1DOB.StartYear = CE.Global.General.GetUTCDateTime().Year - 100;
        usrAdult1DOB.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;

        usrAdult2DOB.StartYear = CE.Global.General.GetUTCDateTime().Year - 100;
        usrAdult2DOB.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;

        usrAdult1DOBSingle.StartYear = CE.Global.General.GetUTCDateTime().Year - 100;
        usrAdult1DOBSingle.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;

        usrAdult2DOBSingle.StartYear = CE.Global.General.GetUTCDateTime().Year - 100;
        usrAdult2DOBSingle.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;

        usrChild1DOB.IsAllowGreaterThanToday = false;
        usrChild1DOB.StartYear = CE.Global.General.GetUTCDateTime().Year - 23;
        usrChild1DOB.EndYear = CE.Global.General.GetUTCDateTime().Year;

        usrChild2DOB.IsAllowGreaterThanToday = false;
        usrChild2DOB.StartYear = CE.Global.General.GetUTCDateTime().Year - 23;
        usrChild2DOB.EndYear = CE.Global.General.GetUTCDateTime().Year;

        usrChild3DOB.IsAllowGreaterThanToday = false;
        usrChild3DOB.StartYear = CE.Global.General.GetUTCDateTime().Year - 23;
        usrChild3DOB.EndYear = CE.Global.General.GetUTCDateTime().Year;

        usrChild4DOB.IsAllowGreaterThanToday = false;
        usrChild4DOB.StartYear = CE.Global.General.GetUTCDateTime().Year - 23;
        usrChild4DOB.EndYear = CE.Global.General.GetUTCDateTime().Year;

        usrChild5DOB.IsAllowGreaterThanToday = false;
        usrChild5DOB.StartYear = CE.Global.General.GetUTCDateTime().Year - 23;
        usrChild5DOB.EndYear = CE.Global.General.GetUTCDateTime().Year;

        usrChild6DOB.IsAllowGreaterThanToday = false;
        usrChild6DOB.StartYear = CE.Global.General.GetUTCDateTime().Year - 23;
        usrChild6DOB.EndYear = CE.Global.General.GetUTCDateTime().Year;

        usrChild1DOBSingle.IsAllowGreaterThanToday = false;
        usrChild1DOBSingle.StartYear = CE.Global.General.GetUTCDateTime().Year - 23;
        usrChild1DOBSingle.EndYear = CE.Global.General.GetUTCDateTime().Year;

        usrChild2DOBSingle.IsAllowGreaterThanToday = false;
        usrChild2DOBSingle.StartYear = CE.Global.General.GetUTCDateTime().Year - 23;
        usrChild2DOBSingle.EndYear = CE.Global.General.GetUTCDateTime().Year;

        usrChild3DOBSingle.IsAllowGreaterThanToday = false;
        usrChild3DOBSingle.StartYear = CE.Global.General.GetUTCDateTime().Year - 23;
        usrChild3DOBSingle.EndYear = CE.Global.General.GetUTCDateTime().Year;

        usrChild4DOBSingle.IsAllowGreaterThanToday = false;
        usrChild4DOBSingle.StartYear = CE.Global.General.GetUTCDateTime().Year - 23;
        usrChild4DOBSingle.EndYear = CE.Global.General.GetUTCDateTime().Year;

        usrBirthday.StartYear = CE.Global.General.GetUTCDateTime().Year - 100;
        usrBirthday.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;

        usrBirthdaySpouse.StartYear = CE.Global.General.GetUTCDateTime().Year - 100;
        usrBirthdaySpouse.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;

        DateTime _TravelDate = CE.Global.General.GetUTCDateTime().AddDays(+1);

        if (Request.UrlReferrer != null)
        {
            if (Request.UrlReferrer.AbsolutePath.ToString().ToLower() != "/travel-flights/results.aspx")
            {
                inputFrom.Value = _TravelDate.ToString("dd/MM/yyyy");
                inputTo.Value = _TravelDate.ToString("dd/MM/yyyy");

                inputannualcomdate.Value = _TravelDate.ToString("dd/MM/yyyy");

            }
        }
        else
        {
            inputFrom.Value = _TravelDate.ToString("dd/MM/yyyy");
            inputTo.Value = _TravelDate.ToString("dd/MM/yyyy");

            inputannualcomdate.Value = _TravelDate.ToString("dd/MM/yyyy");
        }

    }

    private Int64 LogUserViewedHistory()
    {
        UserViewHistoryDB _userviewdb = new UserViewHistoryDB();
        return _userviewdb.LogResultViewedHistory("TA24", Request, "RSA Travel Insurance travel quote.");
    }

    //protected void UpdateTimer1_Tick(object sender, EventArgs e)
    //{

    //    DateTime dtEnd = CE.Global.General.GetUTCDateTime(); // Convert.ToDateTime(_month + "/" + _day + "/20" + _year);
    //    DateTime dtNow = CE.Global.General.GetUTCDateTime();

    //    DataTable dtPromo = CheckPromo("24");
    //    if (dtPromo.Rows.Count > 0)
    //    {
    //        //PromoStartDate = Convert.ToDateTime(dtPromo.Rows[0]["StartDate"].ToString(), System.Globalization.CultureInfo.InvariantCulture);
    //        dtEnd = Convert.ToDateTime(dtPromo.Rows[0]["EndDate"].ToString(), System.Globalization.CultureInfo.InvariantCulture);
    //    }

    //    if (dtNow <= dtEnd)
    //    {
    //        TimeSpan ts = dtEnd - dtNow;

    //        lblTimer1Days.Text = string.Format("{0:00}", ts.Days); //ts.Days.ToString();
    //        lblTimer1Hours.Text = string.Format("{0:00}", ts.Hours);
    //        lblTimer1Minutes.Text = string.Format("{0:00}", ts.Minutes);
    //        lblTimer1Seconds.Text = string.Format("{0:00}", ts.Seconds);
    //    }
    //    else
    //    {
    //        lblTimer1Days.Text = "00";
    //        lblTimer1Hours.Text = "00";
    //        lblTimer1Minutes.Text = "00";
    //        lblTimer1Seconds.Text = "00";

    //        UpdateTimer1.Enabled = false;
    //        Response.Redirect("promo.aspx");
    //    }
    //}

    private DataTable CheckPromo(string providerid)
    {
        MyDatabase _db = new MyDatabase();
        string strSql = "SELECT promotionid, ProviderCompanyId, PromotionType, ItemType, PromotionTitle, PromotionDescription, "
                + "StartDate, EndDate FROM tblCXPromotion WHERE ProviderCompanyId = '" + providerid + "' and PromotionType = 600 "
                + "and GETDATE() between StartDate and EndDate and status = 1";
        DataTable _dt = new DataTable("aTable");
        _dt = _db.GetDataTable(strSql);

        return _dt;

    }

    #region travelsearch

    protected void imgbtnSearch_Click(object sender, EventArgs e)
    {
        CheckValidation();
        if (CheckTravelDateValid())
        {
            if (Page.IsValid)
            {
                if (Session[General.TAId] != null)
                {
                    Cache.Remove("TAResultsQuotes" + Session[General.TAId].ToString());
                }

                Int64 countryid = 0;
                Int64 areaid = 0;
                string coveragelevel = "";
                Int32 duration = 0;
                DateTime startdate = new DateTime(1900, 1, 1);
                DateTime enddate = new DateTime(1900, 1, 1);
                Int32 childage = 0;
                Int32 adultage1 = 0;
                Int32 adultage2 = 0;
                Int32 adultage3 = 0;
                Int32 adultage4 = 0;

                Int32 noofadults = 0;
                DateTime dobadult1 = CE.Global.General.GetUTCDateTime();
                DateTime dobadult2 = CE.Global.General.GetUTCDateTime();
                DateTime dobadult3 = CE.Global.General.GetUTCDateTime();
                DateTime dobadult4 = CE.Global.General.GetUTCDateTime();
                Int32 noofchilds = 0;
                DateTime dobchild1 = CE.Global.General.GetUTCDateTime();
                DateTime dobchild2 = CE.Global.General.GetUTCDateTime();
                DateTime dobchild3 = CE.Global.General.GetUTCDateTime();
                DateTime dobchild4 = CE.Global.General.GetUTCDateTime();
                DateTime dobchild5 = CE.Global.General.GetUTCDateTime();
                DateTime dobchild6 = CE.Global.General.GetUTCDateTime();

                #region scenario logic
                //Response.Write("<script>window.alert('ok')</script>");
                //coveragelevel = ddlCoverage.SelectedValue;

                if (ddlPolicyType.Text == "IND")
                {

                    adultage1 = ComputeAge(usrBirthday.GetDate()); //ComputeAge(usrS1Birthday.GetDate());
                    dobadult1 = usrBirthday.GetDate(); //usrS1Birthday.GetDate();
                    noofadults = 1;
                    noofchilds = 0;

                    if (ddlTripType.SelectedValue == "S")
                    {
                        //Scenario 1
                        countryid = Convert.ToInt64(ddlDestCountry.SelectedValue.ToString());//Convert.ToInt64(ddlS1DestCountry.SelectedValue.ToString());

                        //duration = ComputeDuration(usrTravelStartDate.GetDate(), usrTravelEndDate.GetDate()); //ComputeDuration(usrS1TravelStartDate.GetDate(), usrS1TravelEndDate.GetDate());
                        inputFrom.Value = Request.Form["from"].ToString().Trim();
                        string[] startdateformatted = Request.Form["from"].ToString().Trim().Split('/');
                        string startdate1 = startdateformatted[2] + "-" + startdateformatted[1] + "-" + startdateformatted[0];

                        inputTo.Value = Request.Form["to"].ToString().Trim();
                        string[] enddateformatted = Request.Form["to"].ToString().Trim().Split('/');
                        string enddate1 = enddateformatted[2] + "-" + enddateformatted[1] + "-" + enddateformatted[0];

                        DateTime dtStart = Convert.ToDateTime(startdate1);
                        DateTime dtEnd = Convert.ToDateTime(enddate1);

                        duration = ComputeDuration(dtStart, dtEnd);
                        startdate = dtStart; // usrTravelStartDate.GetDate();
                        enddate = dtEnd; // usrTravelEndDate.GetDate();
                    }
                    else
                    {
                        //Scenario 2
                        areaid = Convert.ToInt64(ddlDestRegion.SelectedValue.ToString()); //Convert.ToInt64(ddlS2DestRegion.SelectedValue.ToString());
                        //startdate = usrPolicyComDate.GetDate();
                        //enddate = usrPolicyComDate.GetDate().AddDays(365);

                        inputannualcomdate.Value = Request.Form["annualcomdate"].ToString().Trim();

                        string[] startdateformatted = Request.Form["annualcomdate"].ToString().Trim().Split('/');
                        string startdate1 = startdateformatted[2] + "-" + startdateformatted[1] + "-" + startdateformatted[0];

                        startdate = Convert.ToDateTime(startdate1);
                        enddate = Convert.ToDateTime(startdate1).AddDays(365);
                    }

                }
                else if (ddlPolicyType.Text == "FML")
                {

                    if (ddlTripType.SelectedValue == "S") //single trip
                    {
                        //Scenario 3          
                        countryid = Convert.ToInt64(ddlDestCountry.SelectedValue.ToString()); //Convert.ToInt64(ddlS3DestCountry.SelectedValue.ToString());

                        inputFrom.Value = Request.Form["from"].ToString().Trim();
                        string[] startdateformatted = Request.Form["from"].ToString().Trim().Split('/');
                        string startdate1 = startdateformatted[2] + "-" + startdateformatted[1] + "-" + startdateformatted[0];

                        inputTo.Value = Request.Form["to"].ToString().Trim();
                        string[] enddateformatted = Request.Form["to"].ToString().Trim().Split('/');
                        string enddate1 = enddateformatted[2] + "-" + enddateformatted[1] + "-" + enddateformatted[0];

                        DateTime dtStart = Convert.ToDateTime(startdate1);
                        DateTime dtEnd = Convert.ToDateTime(enddate1);

                        //duration = ComputeDuration(usrTravelStartDate.GetDate(), usrTravelEndDate.GetDate()); // ComputeDuration(usrS3TravelStartDate.GetDate(), usrS3TravelEndDate.GetDate());                        
                        duration = ComputeDuration(dtStart, dtEnd);

                        startdate = dtStart; // usrTravelStartDate.GetDate();
                        enddate = dtEnd; // usrTravelEndDate.GetDate();
                        adultage1 = ComputeAge(usrAdult1DOBSingle.GetDate());
                        adultage2 = ComputeAge(usrAdult2DOBSingle.GetDate());

                        childage = ComputeAge(usrChild1DOBSingle.GetDate());
                        noofadults = Convert.ToInt32(ddlNoOfAdultsSingle.SelectedValue.ToString());
                        noofchilds = Convert.ToInt32(ddlNoOfChildsSingle.SelectedValue.ToString());

                        for (int i = 1; i <= noofadults; i++)
                        {
                            if (i == 1)
                            {
                                dobadult1 = usrAdult1DOBSingle.GetDate();
                            }
                            if (i == 2)
                            {
                                dobadult2 = usrAdult2DOBSingle.GetDate();
                            }

                        }
                        for (int j = 1; j <= noofchilds; j++)
                        {
                            if (j == 1)
                            {
                                dobchild1 = usrChild1DOBSingle.GetDate();
                            }
                            if (j == 2)
                            {
                                dobchild2 = usrChild2DOBSingle.GetDate();
                            }
                            if (j == 3)
                            {
                                dobchild3 = usrChild3DOBSingle.GetDate();
                            }
                            if (j == 4)
                            {
                                dobchild4 = usrChild4DOBSingle.GetDate();
                            }

                        }
                    }
                    else //annual trip
                    {
                        //Scenario 4
                        areaid = Convert.ToInt64(ddlDestRegion.SelectedValue.ToString()); //Convert.ToInt64(ddlS4DestRegion.SelectedValue.ToString());

                        // startdate = usrPolicyComDate.GetDate(); // usrTravelStartDate.GetDate(); // usrS3TravelStartDate.GetDate();
                        //enddate = usrPolicyComDate.GetDate().AddDays(365);

                        inputannualcomdate.Value = Request.Form["annualcomdate"].ToString().Trim();

                        string[] startdateformatted = Request.Form["annualcomdate"].ToString().Trim().Split('/');
                        string startdate1 = startdateformatted[2] + "-" + startdateformatted[1] + "-" + startdateformatted[0];

                        startdate = Convert.ToDateTime(startdate1);
                        enddate = Convert.ToDateTime(startdate1).AddDays(365);

                        adultage1 = ComputeAge(usrAdult1DOB.GetDate()); // ComputeAge(usrS3Adult1DOB.GetDate());
                        adultage2 = ComputeAge(usrAdult2DOB.GetDate()); //ComputeAge(usrS3Adult2DOB.GetDate());

                        childage = ComputeAge(usrChild1DOB.GetDate()); //ComputeAge(usrS3Child1DOB.GetDate());
                        noofadults = Convert.ToInt32(ddlNoOfAdults.SelectedValue.ToString()); //Convert.ToInt32(ddlS3NoOfAdults.SelectedValue.ToString());
                        noofchilds = Convert.ToInt32(ddlNoOfChilds.SelectedValue.ToString());  //Convert.ToInt32(ddlS3NoOfChilds.SelectedValue.ToString());

                        for (int i = 1; i <= noofadults; i++)
                        {
                            if (i == 1)
                            {
                                dobadult1 = usrAdult1DOB.GetDate(); //usrS3Adult1DOB.GetDate();
                            }
                            if (i == 2)
                            {
                                dobadult2 = usrAdult2DOB.GetDate(); //usrS3Adult2DOB.GetDate();
                            }

                        }
                        for (int j = 1; j <= noofchilds; j++)
                        {
                            if (j == 1)
                            {
                                dobchild1 = usrChild1DOB.GetDate(); //usrS3Child1DOB.GetDate();
                            }
                            if (j == 2)
                            {
                                dobchild2 = usrChild2DOB.GetDate(); //usrS3Child2DOB.GetDate();
                            }
                            if (j == 3)
                            {
                                dobchild3 = usrChild3DOB.GetDate(); //usrS3Child3DOB.GetDate();
                            }
                            if (j == 4)
                            {
                                dobchild4 = usrChild4DOB.GetDate(); //usrS3Child4DOB.GetDate();
                            }
                            if (j == 5)
                            {
                                dobchild5 = usrChild5DOB.GetDate(); //usrS3Child5DOB.GetDate();
                            }
                            if (j == 6)
                            {
                                dobchild6 = usrChild6DOB.GetDate(); //usrS3Child6DOB.GetDate();
                            }
                        }
                    }

                }
                else if (ddlPolicyType.Text == "INS")
                {

                    adultage1 = ComputeAge(usrBirthday.GetDate()); ;
                    adultage2 = ComputeAge(usrBirthdaySpouse.GetDate());
                    dobadult1 = usrBirthday.GetDate();
                    dobadult2 = usrBirthdaySpouse.GetDate();
                    noofadults = 2;
                    noofchilds = 0;

                    if (ddlTripType.SelectedValue == "S")
                    {
                        //Scenario 5

                        inputFrom.Value = Request.Form["from"].ToString().Trim();
                        string[] startdateformatted = Request.Form["from"].ToString().Trim().Split('/');
                        string startdate1 = startdateformatted[2] + "-" + startdateformatted[1] + "-" + startdateformatted[0];

                        inputTo.Value = Request.Form["to"].ToString().Trim();
                        string[] enddateformatted = Request.Form["to"].ToString().Trim().Split('/');
                        string enddate1 = enddateformatted[2] + "-" + enddateformatted[1] + "-" + enddateformatted[0];

                        DateTime dtStart = Convert.ToDateTime(startdate1);
                        DateTime dtEnd = Convert.ToDateTime(enddate1);

                        startdate = dtStart; // usrTravelStartDate.GetDate();
                        enddate = dtEnd; // usrTravelEndDate.GetDate();
                        countryid = Convert.ToInt64(ddlDestCountry.SelectedValue.ToString());
                        duration = ComputeDuration(dtStart, dtEnd);

                    }
                    else
                    {
                        //Scenario 6
                        areaid = Convert.ToInt64(ddlDestRegion.SelectedValue.ToString());
                        adultage1 = ComputeAge(usrBirthday.GetDate());
                        adultage2 = ComputeAge(usrBirthdaySpouse.GetDate());

                        //startdate = usrPolicyComDate.GetDate(); // usrTravelStartDate.GetDate(); // usrS3TravelStartDate.GetDate();
                        //enddate = usrPolicyComDate.GetDate().AddDays(365);

                        inputannualcomdate.Value = Request.Form["annualcomdate"].ToString().Trim();

                        string[] startdateformatted = Request.Form["annualcomdate"].ToString().Trim().Split('/');
                        string startdate1 = startdateformatted[2] + "-" + startdateformatted[1] + "-" + startdateformatted[0];

                        startdate = Convert.ToDateTime(startdate1);
                        enddate = Convert.ToDateTime(startdate1).AddDays(365);

                    }

                }



                string[] customerage = { adultage1.ToString(), adultage2.ToString(), adultage3.ToString(), adultage4.ToString() };
                Session[General.TACustomerAge] = customerage;


                #endregion

                TAApplicantSearch _taapplicantsearch = new TAApplicantSearch();
                TAApplicantSearchDB _taapplicantsearchdb = new TAApplicantSearchDB();

                if (Session[General.TAId] == null)
                {
                    _taapplicantsearch.TAAppSeaId = 0;
                }
                else
                {
                    _taapplicantsearch.TAAppSeaId = Convert.ToInt64(Session[General.TAId].ToString());
                }

                //Sakthi on 15 Feb 2011 -- Start
                //if (Session[General.UserId] == null)
                //{
                //    _taapplicantsearch.RefCEUserId = CheckAndCreateAndSendMailToUser();
                //}
                //else
                //{
                //    _taapplicantsearch.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
                //    SendMailToUser(_taapplicantsearch.RefCEUserId, true, Session[General.UserEmail].ToString(), Session[General.UserName].ToString(), "");
                //}

                //_taapplicantsearch.Name = ""; // txtOwnerName.Text.Trim();
                //_taapplicantsearch.EmailAddress = ""; // txtOwnerEmailAddress.Text.Trim();
                //_taapplicantsearch.MobileNum = ""; // txtOwnerPhoneNo.GetPhoneNo().ToString();

                if (Session[General.UserId] == null)
                {
                    _taapplicantsearch.RefCEUserId = 0;
                    _taapplicantsearch.Name = "";// txtFullName.Text.ToUpper();
                    _taapplicantsearch.EmailAddress = ""; // txtEmail.Text;
                    _taapplicantsearch.MobileNum = ""; // txtMobileNo.GetPhoneNo();
                }
                else
                {
                    _taapplicantsearch.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
                    _taapplicantsearch.Name = Session[General.UserName].ToString();
                    _taapplicantsearch.EmailAddress = Session[General.UserEmail].ToString();
                    _taapplicantsearch.MobileNum = Session[General.UserPhoneNo].ToString();
                }
                //Sakthi on 15 Feb 2011 -- End

                _taapplicantsearch.PlanType = ddlPolicyType.SelectedValue.ToString();
                _taapplicantsearch.TripType = ddlTripType.SelectedValue.ToString();
                _taapplicantsearch.CountryID = countryid;
                _taapplicantsearch.AreaID = areaid;
                _taapplicantsearch.CoverageLevel = coveragelevel;
                _taapplicantsearch.Duration = duration;
                _taapplicantsearch.StartDate = startdate;
                _taapplicantsearch.EndDate = enddate;
                _taapplicantsearch.ChildAge = childage;
                _taapplicantsearch.AdultAge = adultage1;
                _taapplicantsearch.NoOfTravellers = noofadults + noofchilds;//GetNoOfTravellers();
                _taapplicantsearch.TotalPremium = 0;

                _taapplicantsearch.NoofAdults = noofadults;
                _taapplicantsearch.DOBAdult1 = dobadult1;
                _taapplicantsearch.DOBAdult2 = dobadult2;
                _taapplicantsearch.DOBAdult3 = dobadult3;
                _taapplicantsearch.DOBAdult4 = dobadult4;
                _taapplicantsearch.NoofChilds = noofchilds;
                _taapplicantsearch.DOBChild1 = dobchild1;
                _taapplicantsearch.DOBChild2 = dobchild2;
                _taapplicantsearch.DOBChild3 = dobchild3;
                _taapplicantsearch.DOBChild4 = dobchild4;
                _taapplicantsearch.DOBChild5 = dobchild5;
                _taapplicantsearch.DOBChild6 = dobchild6;

                if (Session[General.ViewedDetailsId] == null)
                {
                    _taapplicantsearch.ViewedDetailId = 0;
                }
                else
                {
                    _taapplicantsearch.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                }

                if (inputPID.Value.Trim() != "")
                {
                    Int64 iPID = Convert.ToInt64(inputPID.Value.Trim());
                    _taapplicantsearch.Ninfo3 = iPID;
                }
                else
                {
                    _taapplicantsearch.Ninfo3 = 0;
                }

                _taapplicantsearch.Info1 = "1";
                Int64 _result = _taapplicantsearchdb.Insert(_taapplicantsearch);

                if (_result > 0)
                {
                    Session["TripType"] = ddlTripType.Text;
                    Session["PlanType"] = _taapplicantsearch.PlanType;
                    Session[General.TAId] = _result.ToString();

                    if (Session[General.UserId] == null)
                    {
                        Session[General.TAPersonnelId] = _taapplicantsearch.RefCEUserId.ToString();
                        Session[General.TAUserName] = ""; // txtFullName.Text.ToUpper();
                        Session[General.TAPhoneNo] = ""; //txtMobileNo.GetPhoneNo().ToString();
                        Session[General.TAEmail] = ""; //txtEmail.Text;
                    }

                    Int64 TAAppSeaId = Convert.ToInt64(Session[General.TAId].ToString());
                    string Status = "2";
                    Int64 _updateresult = _taapplicantsearchdb.UpdateStatus(TAAppSeaId, Status);
                    if (_updateresult > 0)
                    {
                        //Response.Redirect("taresultsquotesone.aspx");

                        ResultsQuotesDataBind();


                        Response.Redirect("rsa-july-travel-insurance-results.aspx");

                    }
                }

                LogUserViewedHistory();
            }
        }
    }

    private void ResultsQuotesDataBind()
    {
        if (Cache["TAResultsQuotes" + Session[General.TAId].ToString()] == null)
            GetTempResultTable();

        DataView dv = new DataView((DataTable)Cache["TAResultsQuotes" + Session[General.TAId].ToString()]);

        if (dv.Count > 0)
        {
            RowCount = dv.Count;

            if (Request.UrlReferrer != null)
            {
                Session["DefaultSort"] = null;
                Session["SortExp"] = null;

                dv.Sort = "AnnualPremium ASC";

                Cache["TAResultsQuotes" + Session[General.TAId].ToString()] = dv.ToTable();

            }

            string sQueryString = "";

            for (int i = 0; i < dv.ToTable().Rows.Count; i++)
            {
                if (i == 7)
                {
                    break;
                }

                string skey = dv.ToTable().Rows[i]["TAInsID"].ToString();
                sQueryString += skey + ",";
            }


            Session["TASelected"] = sQueryString;

        }

    }

    private void GetTempResultTable()
    {
        string CoverType = "";
        Int32 Duration = 0;
        string CoverageLevel = "";
        string Trip = "";
        Int64 AreaId = 0;
        Int64 CountryId = 0;
        Int32 AdultAge = 0;
        Int32 ChildAge = 0;
        Int64 TAId = 0;
        Int32 NoOfAdults = 0;
        Int32 NoOfChilds = 0;

        TAApplicantSearchDB _taapplicantsearchdb = new TAApplicantSearchDB();
        TAApplicantSearch _taapplicantsearch = new TAApplicantSearch();

        if (Session[General.TAId] != null && Session[General.TAId].ToString() != "")
            TAId = Convert.ToInt64(Session[General.TAId].ToString());
        else
        {
            this.Page_Load(this, null);
        }

        _taapplicantsearch = _taapplicantsearchdb.GetTAApplicantSearchItem(TAId);

        if (_taapplicantsearch != null)
        {
            //Response.Write("<script>window.alert('ok ')</script>");
            CoverType = _taapplicantsearch.PlanType;
            Duration = _taapplicantsearch.Duration;
            AreaId = _taapplicantsearch.AreaID;
            CountryId = _taapplicantsearch.CountryID;
            AdultAge = _taapplicantsearch.AdultAge;
            ChildAge = _taapplicantsearch.ChildAge;
            CoverageLevel = _taapplicantsearch.CoverageLevel;
            Trip = _taapplicantsearch.TripType;
            NoOfAdults = _taapplicantsearch.NoofAdults;
            NoOfChilds = _taapplicantsearch.NoofChilds;
            MyDatabase _db = new MyDatabase();
            DataTable _dtResult = new DataTable();


            TAQuoteResultDB _taquoteresultdb = new TAQuoteResultDB();

            //rsa only = 24

            _dtResult = _taquoteresultdb.GetTAQuoteResultDisplayByProvider(GetCovertype(CoverType), Duration.ToString(), AreaId, CountryId, AdultAge, ChildAge, CoverageLevel, 24, NoOfAdults, NoOfChilds, TAId);
            RowCount = _dtResult.Rows.Count;

            DataView dv = new DataView(_dtResult);
            string strSortExpress = "AnnualPremium ASC";

            dv.Sort = strSortExpress;
            Cache["TAResultsQuotes" + Session[General.TAId].ToString()] = dv.ToTable();

        }
        else
        {
            this.Page_Load(this, null);

        }

    }

    private string GetCovertype(string covertype)
    {
        string coverparam = "";
        if (covertype == "IND")
            coverparam = "Individual";
        else if (covertype == "INS")
            coverparam = "IndividualSpouse";
        else if (covertype == "FML")
            coverparam = "Family";
        else if (covertype == "INC")
            coverparam = "IndividualChild";

        return coverparam;
    }

    private void CheckValidation()
    {

        usrBirthday.IsEnableValidation(false);
        usrBirthdaySpouse.IsEnableValidation(false);
        //usrTravelStartDate.IsEnableValidation(false);
        //usrTravelEndDate.IsEnableValidation(false);
        //usrPolicyComDate.IsEnableValidation(false);

        rfvCountry.Enabled = false;
        rfvDestCountry.Enabled = false;
        rfvDestRegion.Enabled = false;
        rfvNoOfAdults.Enabled = false;
        rfvNoOfChilds.Enabled = false;
        rfvNoOfAdultsSingle.Enabled = false;
        rfvNoOfChildsSingle.Enabled = false;

        usrAdult1DOB.IsEnableValidation(false);
        usrAdult2DOB.IsEnableValidation(false);
        usrAdult1DOBSingle.IsEnableValidation(false);
        usrAdult2DOBSingle.IsEnableValidation(false);

        usrChild1DOB.IsEnableValidation(false);
        usrChild2DOB.IsEnableValidation(false);
        usrChild3DOB.IsEnableValidation(false);
        usrChild4DOB.IsEnableValidation(false);
        usrChild5DOB.IsEnableValidation(false);
        usrChild6DOB.IsEnableValidation(false);

        usrChild1DOBSingle.IsEnableValidation(false);
        usrChild2DOBSingle.IsEnableValidation(false);
        usrChild3DOBSingle.IsEnableValidation(false);
        usrChild4DOBSingle.IsEnableValidation(false);

        if (ddlTripType.SelectedValue == "S") //(snum.Value == "1") 
        {
            //usrTravelEndDate.IsEnableValidation(true);
            //usrTravelStartDate.IsEnableValidation(true);
            rfvDestCountry.Enabled = true;
            rfvCountry.Enabled = true;

        }
        else if (ddlTripType.SelectedValue == "A") //(snum.Value == "2")        
        {
            //usrPolicyComDate.IsEnableValidation(true);
            rfvDestRegion.Enabled = true;

        }

        if (ddlPolicyType.SelectedValue == "IND") //(snum.Value == "3")
        {
            usrBirthday.IsEnableValidation(true);

        }
        else if (ddlPolicyType.SelectedValue == "FML") //(snum.Value == "4") 
        {
            rfvNoOfAdults.Enabled = true;
            rfvNoOfChilds.Enabled = true;

            if (ddlTripType.SelectedValue == "S")
            {
                if (ddlNoOfAdultsSingle.SelectedValue == "1")
                {
                    usrAdult1DOBSingle.IsEnableValidation(true);
                }

                if (ddlNoOfAdultsSingle.SelectedValue == "2")
                {
                    usrAdult1DOBSingle.IsEnableValidation(true);
                    usrAdult2DOBSingle.IsEnableValidation(true);
                }

                if (ddlNoOfChildsSingle.SelectedValue == "1")
                {
                    usrChild1DOBSingle.IsEnableValidation(true);
                }

                if (ddlNoOfChildsSingle.SelectedValue == "2")
                {
                    usrChild1DOBSingle.IsEnableValidation(true);
                    usrChild2DOBSingle.IsEnableValidation(true);
                }

                if (ddlNoOfChildsSingle.SelectedValue == "3")
                {
                    usrChild1DOBSingle.IsEnableValidation(true);
                    usrChild2DOBSingle.IsEnableValidation(true);
                    usrChild3DOBSingle.IsEnableValidation(true); ;
                }

                if (ddlNoOfChildsSingle.SelectedValue == "4")
                {
                    usrChild1DOBSingle.IsEnableValidation(true);
                    usrChild2DOBSingle.IsEnableValidation(true);
                    usrChild3DOBSingle.IsEnableValidation(true);
                    usrChild4DOBSingle.IsEnableValidation(true);
                }

            }
            else
            {

                if (ddlNoOfAdults.SelectedValue == "1")
                {
                    usrAdult1DOB.IsEnableValidation(true);

                }

                if (ddlNoOfAdults.SelectedValue == "2")
                {
                    usrAdult1DOB.IsEnableValidation(true);
                    usrAdult2DOB.IsEnableValidation(true);
                }


                if (ddlNoOfChilds.SelectedValue == "1")
                {
                    usrChild1DOB.IsEnableValidation(true);
                }

                if (ddlNoOfChilds.SelectedValue == "2")
                {
                    usrChild1DOB.IsEnableValidation(true);
                    usrChild2DOB.IsEnableValidation(true);
                }

                if (ddlNoOfChilds.SelectedValue == "3")
                {
                    usrChild1DOB.IsEnableValidation(true);
                    usrChild2DOB.IsEnableValidation(true);
                    usrChild3DOB.IsEnableValidation(true); ;
                }

                if (ddlNoOfChilds.SelectedValue == "4")
                {
                    usrChild1DOB.IsEnableValidation(true);
                    usrChild2DOB.IsEnableValidation(true);
                    usrChild3DOB.IsEnableValidation(true);
                    usrChild4DOB.IsEnableValidation(true);
                }


                if (ddlNoOfChilds.SelectedValue == "5")
                {
                    usrChild1DOB.IsEnableValidation(true);
                    usrChild2DOB.IsEnableValidation(true);
                    usrChild3DOB.IsEnableValidation(true);
                    usrChild4DOB.IsEnableValidation(true);
                    usrChild5DOB.IsEnableValidation(true);
                }

                if (ddlNoOfChilds.SelectedValue == "6")
                {
                    usrChild1DOB.IsEnableValidation(true);
                    usrChild2DOB.IsEnableValidation(true);
                    usrChild3DOB.IsEnableValidation(true);
                    usrChild4DOB.IsEnableValidation(true);
                    usrChild5DOB.IsEnableValidation(true);
                    usrChild6DOB.IsEnableValidation(true);
                }
            }
        }
        else if (ddlPolicyType.SelectedValue == "INS") //(snum.Value == "5") 
        {
            usrBirthday.IsEnableValidation(true);
            usrBirthdaySpouse.IsEnableValidation(true);

            //Response.Write("<script>window.alert('individ+spouse')</script>");
        }


    }

    private int GetNoOfTravellers()
    {
        int travellers = 0;

        if (ddlPolicyType.SelectedValue == "IND")
            travellers = 1;
        else if (ddlPolicyType.SelectedValue == "INS")
        {
            travellers = 2;
        }
        else
        {
            travellers = Convert.ToInt32(ddlNoOfAdults.Text) + Convert.ToInt32(ddlNoOfChilds.Text);
        }

        return travellers;
    }

    private int ComputeDuration(DateTime dtFrom, DateTime dtTo)
    {
        int TripDuration = 0;
        TripDuration = Convert.ToInt32(dtTo.Subtract(dtFrom).TotalDays.ToString());
        TripDuration = TripDuration + 1;

        return TripDuration;
    }

    private int ComputeAge(DateTime dtBirth)
    {
        int Age = 0;

        DateTime now = CE.Global.General.GetUTCDateTime();// DateTime.Today;
        Age = now.Year - dtBirth.Year;
        // subtract another year if we're before the birthday in the current year
        if (now.Month < dtBirth.Month || (now.Month == dtBirth.Month && now.Day < dtBirth.Day))
            --Age;

        return Age;
    }

    private bool CheckTravelDateValid()
    {
        bool _IsValid = true;
        DateTime _Date = CE.Global.General.GetUTCDateTime();
        DateTime _TravelFromDate = CE.Global.General.GetUTCDateTime();
        DateTime _TravelToDate = CE.Global.General.GetUTCDateTime();

        if (ddlTripType.SelectedValue == "S")
        {

            string[] startdateformatted = Request.Form["from"].ToString().Trim().Split('/');
            string startdate = startdateformatted[2] + "-" + startdateformatted[1] + "-" + startdateformatted[0];

            string[] enddateformatted = Request.Form["to"].ToString().Trim().Split('/');
            string enddate = enddateformatted[2] + "-" + enddateformatted[1] + "-" + enddateformatted[0];

            DateTime dtStart = Convert.ToDateTime(startdate);
            DateTime dtEnd = Convert.ToDateTime(enddate);

            _TravelFromDate = dtStart; //usrTravelStartDate.GetDate();
            _TravelToDate = dtEnd; //usrTravelEndDate.GetDate();
        }

        if (_TravelFromDate >= _Date)
        {
            if (_TravelToDate >= _TravelFromDate)
            {
                _IsValid = true;
            }
            else
            {
                _IsValid = false;
            }
        }
        else
        {
            _IsValid = false;
        }
        return _IsValid;
    }



    #endregion
}
